﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LarDosIdosos.Business.Model;

namespace LarDosIdosos
{
    public partial class UserControlMenu : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ValidaMenu();
            ExibeLinkButtonLogin();
        }

        /// <summary>
        /// Limpa a sessão usuário e redireciona para a página inicial
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void linkButtonLogout_OnClick(object sender, EventArgs e)
        {
            Session["usuario"] = null;
            Response.Redirect("~/Default.aspx");
        }

        /// <summary>
        /// Exibe os menus de acordo com o usuário logado
        /// </summary>
        private void ValidaMenu()
        {
            LarDosIdosos.Business.Model.Funcionario funcionario = (LarDosIdosos.Business.Model.Funcionario)Session["usuario"];
            if (funcionario != null)
            {
                switch (funcionario.Cargo_Funcionario.CodigoCargo)
                {
                    case 1:
                        ExibeMenuAdministrador();
                        break;
                    case 2:
                        ExibeMenuAssistenteSocial();
                        break;
                    case 3:
                        ExibeMenuAmoxarife();
                        break;
                    case 4:
                        ExibeMenuMedico();
                        break;
                    case 5:
                        ExibeMenuTecEnfermagem();
                        break;

                }
            }
        }

        private void ExibeMenuAssistenteSocial()
        {
			menuAssistenteSocial.Visible = true;
            //NavigationMenu.Items.Add(new MenuItem("Idosos", "menuIdosos", null, "Idosos.aspx"));
        }

        private void ExibeMenuAmoxarife()
        {
			menuAlmoxarife.Visible = true;
//            NavigationMenu.Items.Add(new MenuItem("Alimentos", "menuAlimentos", null, "Alimentos.aspx"));
//
//            NavigationMenu.Items.Add(new MenuItem("Higiene", "menuHigiene", null, "Higiene.aspx"));
//
//            NavigationMenu.Items.Add(new MenuItem("Medicamentos", "menuMedicamentos", null, "Medicamentos.aspx"));
        }

        private void ExibeMenuMedico()
        {
			
			menuMedico.Visible = true;
//            NavigationMenu.Items.Add(new MenuItem("Idosos", "menuIdosos", null, "Idosos.aspx"));
//
//            NavigationMenu.Items.Add(new MenuItem("Prontuário", "menuProntuario", null, "Prontuario.aspx"));
        }

        private void ExibeMenuTecEnfermagem()
        {
			menuTecEnfermagem.Visible = true;
//            NavigationMenu.Items.Add(new MenuItem("Idosos", "menuIdosos", null, "Idosos.aspx"));
//
//            NavigationMenu.Items.Add(new MenuItem("Prontuário", "menuProntuario", null, "Prontuario.aspx"));
        }

        private void ExibeLinkButtonLogin()
        {
            if(Session["usuario"] != null)
            {
                linkButtonLogout.Visible = true;
            }
            else
            {
                linkButtonLogout.Visible = false;
            }
        }

        private void ExibeMenuAdministrador()
        {
			menuAdministrador.Visible = true;
//			NavigationMenu.StaticMenuStyle.Width = 100;
//			
//            NavigationMenu.Items.Add(new MenuItem("Responsável", "menuResp", null, "Responsavel.aspx"));
//
//            NavigationMenu.Items.Add(new MenuItem("Funcionário", "menufuncionario", null, "Funcionarios.aspx"));
//
//            NavigationMenu.Items.Add(new MenuItem("Parceiros", "menuParceiro", null, "Parceiros.aspx"));
//
//            NavigationMenu.Items.Add(new MenuItem("Visitante", "menuVisitante", null, "Visitante.aspx"));
//
//            NavigationMenu.Items.Add(new MenuItem("Doação", "menuDoacao", null, "Doacao.aspx"));

        }
    }
}